package cn.spingboot.controller;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;
@ControllerAdvice
public class GlobalExceptionHandler {
    /*全局捕获异常类*/
    @ExceptionHandler(RuntimeException.class)
     @ResponseBody/*返回json类型 如果返回404页面 不需要 默认是字符串类型*/
    public Map<String,Object> resultError(){
        Map<String,Object> result = new HashMap<String ,Object>();
        result.put("errorCode",500);
        result.put("errorMsg","系统有误！");
        return result   ;
    }
}
